package cn.wangjun.org.service.impl;

import cn.wangjun.basic.util.PageList;
import cn.wangjun.org.domain.Department;
import cn.wangjun.org.mapper.DepartmentMapper;
import cn.wangjun.org.query.DepartmentQuery;
import cn.wangjun.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Transactional
    @Override
    public void add(Department d) {
        departmentMapper.save(d);
    }
    @Transactional
    @Override
    public void upadte(Department d) {
        departmentMapper.update(d);
    }
    @Transactional
    @Override
    public void del(Long id) {
        departmentMapper.remove(id);
    }

    @Override
    public Department getById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    public List<Department> getAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> queryData(DepartmentQuery query) {
        //获取的总条数
        Long totals = departmentMapper.queryCount(query);
        //每页数据
        List<Department> list = departmentMapper.queryData(query);

        return new PageList<>(totals,list);
    }

    @Override
    public void patchDelete(List<Long> ids) {
        departmentMapper.patchDelete(ids);
    }

    @Override
    public List<Department> getTree() {
        return departmentMapper.getTree();
    }
}
